package com.hm.manage.pach;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetRequestExample {
    public static void main(String[] args) {
        try {
            URL url = new URL("http://psvs.szpt.ga/api/systemArchive/archiveDetail/320412010001202504281602400000001");
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); // 强制转换为 HttpURLConnection 以使用其特定功能（如设置请求方法）
            httpURLConnection.setRequestMethod("GET"); // 设置请求方法为 GET（默认即为 GET，但显式设置有助于清晰）
            httpURLConnection.setRequestProperty("Accept", "application/json, text/plain, */*"); // 设置请求头（可选）
            httpURLConnection.setRequestProperty("Cookie", "JSESSIONID=A8E9AFAC681B87769287198440A55D08");
            httpURLConnection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
            httpURLConnection.setRequestProperty("x-access-token","00a8d4f653f44800ae7959b490a44ed6");

            httpURLConnection.connect(); // 建立连接并发送请求（对于 GET 请求，通常不需要额外的发送步骤）
            InputStream inputStream = httpURLConnection.getInputStream(); // 获取输入流来读取响应内容（对于 GET 请求）
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            StringBuilder response = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            inputStream.close();
            System.out.println(response.toString()); // 打印响应内容
        } catch (Exception e) {
        }
    }
}